-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: linting fixes #261
chore: linting fixes #261
Conversation
@@ -3,10 +3,10 @@ import type { Meta, StoryObj } from '@storybook/react'; | |||
import { Text, TextColor } from '@metamask/design-system-react'; | |||
import README from './Shadows.mdx'; | |||
|
|||
interface ShadowSwatchProps { | |||
type ShadowSwatchProps = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use type instead of interface
@@ -2,7 +2,7 @@ import React, { FunctionComponent } from 'react'; | |||
import { lightTheme } from '../../../src'; | |||
import { Text, TextVariant } from '@metamask/design-system-react'; | |||
|
|||
interface ColorSwatchProps { | |||
type ColorSwatchProps = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use type instead of interface
import { Text, TextVariant } from '@metamask/design-system-react'; | ||
|
||
interface ColorSwatchGroupProps { | ||
type ColorSwatchGroupProps = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use type instead of interface
packages/design-tokens/tsconfig.json
Outdated
"jsx": "react", | ||
"types": ["react", "node", "jest"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs jsx and react for stories
"stories/**/*.tsx", | ||
"stories/**/*.ts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Includes stories folder in typescript checks but does not include them in build because we are excluding storybook files in tsconfig.packages.build.json
935e228
to
647f03e
Compare
.eslintrc.js
Outdated
'@typescript-eslint/consistent-type-imports': [ | ||
'error', | ||
{ | ||
prefer: 'type-imports', | ||
disallowTypeAnnotations: true, | ||
fixStyle: 'separate-type-imports', | ||
}, | ||
], | ||
'@typescript-eslint/no-import-type-side-effects': 'error', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ESLint rule enforces using import type
syntax for type imports, which helps prevent runtime errors in .mjs
files where type imports aren't supported. It ensures type imports are properly separated from value imports, making the code more maintainable and compatible with ECMAScript modules.
Before
Accidentally included types in mjs files and there is no linting rule preventing this

After

Linting rule

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert changes already in the MM eslint plugin https://github.com/MetaMask/eslint-config/blob/733b9e2835c5422a2f222b23cf373f4050936409/packages/typescript/src/index.mjs#L48
"lint:dependencies": "depcheck && yarn dedupe --check", | ||
"lint:dependencies:fix": "depcheck && yarn dedupe", | ||
"lint:eslint": "eslint . --cache --ext js,cjs,mjs,ts", | ||
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write && yarn constraints --fix && yarn lint:dependencies:fix", | ||
"lint:eslint": "eslint . --cache --ext js,cjs,mjs,ts,tsx", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added .tsx
extension to ESLint configuration to ensure React TypeScript components are properly linted. This helps maintain consistent code quality across both JavaScript and TypeScript React and React Native files in our codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1,6 +1,7 @@ | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint fixes for Text stories now we are including tsx
files
type="button" | ||
onClick={() => { | ||
// eslint-disable-next-line no-alert, no-restricted-globals | ||
alert('button-clicked'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was previously using storybook-actions but once we add it as a dev dependency it clashes with the @storybook/addon-actions version we can fix it in a subsequent PR
@@ -1,8 +1,10 @@ | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint fixes
@@ -52,6 +52,7 @@ | |||
"devDependencies": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding missing dev dependency
@@ -1,13 +1,14 @@ | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint fixes
@@ -1,16 +1,16 @@ | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint fixes
@@ -1,26 +1,27 @@ | |||
/* eslint-disable no-restricted-globals */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint fixes and ignoring no-restriced-globals so we can get the CSS variables from the stylesheet for typography CSS variables
@@ -1,4 +1,5 @@ | |||
import type { Meta, StoryObj } from '@storybook/react'; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint fixes
@@ -1,8 +1,10 @@ | |||
import React, { FunctionComponent } from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint fixes
@@ -1,4 +1,5 @@ | |||
import type { Meta, StoryObj } from '@storybook/react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint fixes
@@ -1,10 +1,11 @@ | |||
import { Text, TextVariant } from '@metamask/design-system-react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint fixes
@@ -0,0 +1,15 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For mdx files similarly to design-system-react
"paths": { | ||
"@metamask/design-system-react": ["../design-system-react/src"] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a6f6215
to
bd8594a
Compare
@@ -1,3 +1,4 @@ | |||
/* eslint-disable import/unambiguous */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,19 @@ | |||
module.exports = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added .eslintrc.js
to support browser environment in React package
This ESLint configuration extends the root config but adds browser-specific settings. The root ESLint config is Node.js-focused, so this configuration:
- Enables browser environment
- Disables Node.js environment
- Turns off
no-restricted-globals
rule to allow browser globals - Adds TypeScript configuration for .ts/.tsx files
bd8594a
to
7f9c649
Compare
rules: { | ||
'no-restricted-globals': 'off', | ||
}, | ||
ignorePatterns: ['scripts/create-component/ComponentName/**'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring component template files
7f9c649
to
425d17f
Compare
Description
This pull request implements several important TypeScript and linting improvements to enhance code quality and developer experience. Key changes include:
.tsx
extension to ESLint configuration to ensure proper linting of React TypeScript components@metamask/design-system-react
to enable direct imports and proper IDE supportimport type
syntax through ESLint to prevent runtime errors in.mjs
filesstories
folder and its files for design-tokensprettier
to apply consistent formatting across all affected filesThese changes collectively improve code maintainability, type safety, and development workflow efficiency.
Related issues
Fixes: N/A
Manual testing steps
yarn lint
and ensure there are no TypeScript linting errorsyarn prettier .
to verify that all files adhere to the formatting rulesPre-merge author checklist
Pre-merge reviewer checklist